package Day35.listTest.Test03;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author hyhWTX
 * @version 1.0
 * @ClassName ShopTest
 * @date 2022年08月05日 19:09
 * @Description: TODO (一句话描述以下该类的功能)
 */
public class ShopTest {
    public static void main(String[] args) {
        ArrayList<Shops> arrayList = new ArrayList<>();
        //展示商品
        ShowShop(arrayList);

        while (true){
            menu(arrayList);
            int i = chooseNumber(arrayList);
            switch (i){
                case 1:
                    printArrayList(arrayList);
                    break;
                case 2:
                    addCount(arrayList);
                    break;
                case 3:
                    delete(arrayList);
                    break;
                case 4:
                    UpDate(arrayList);
                    break;
                case 5:
                    exit();
                    return;
                default:
                    System.out.println("请输入正确的操作序号:");
            }
        }
       
    }
    //初始化商品数据
    public static  void ShowShop(ArrayList<Shops> arrayList){
        Shops shops1 = new Shops();
        shops1.proNum = 1;
        shops1.proName="辣条";
        shops1.proPrice = 5;
        shops1.count = 100;


        Shops shops2 = new Shops();
        shops2.proNum = 2;
        shops2.proName="点心";
        shops2.proPrice = 8;
        shops2.count = 500;

        Shops shops3 = new Shops();
        shops3.proNum = 3;
        shops3.proName="榴莲";
        shops3.proPrice = 10;
        shops3.count = 200;

        //存储起来
        arrayList.add(shops1);
        arrayList.add(shops2);
        arrayList.add(shops3);

    }
    //显示菜单
    public static void menu(ArrayList<Shops> array){
        System.out.println();
        System.out.println("===================欢迎光临oracle超市====================");
        System.out.println("1.查看商品清单" + "  " + "2.添加新商品" + "  " + "3.删除商品"
                + "  " + "4.修改商品" + "  " + "5.退出");
        System.out.println("请您输入要操作的功能序号：");
    }
    //选择序号功能
    public static int chooseNumber(ArrayList<Shops> array){
        // 键盘键入功能序号
        Scanner in = new Scanner(System.in);
        int number = in.nextInt();
        return number;
    }

    //查看货物
    public static void printArrayList(ArrayList<Shops> array){
        System.out.println("============超市库存清单============");
        System.out.println("商品编号" + "   " + "商品名称" + "   " + "商品单价" + "   "
                + "商品库存");
        int totalCount = 0;
        for (int i = 0; i < array.size(); i++) {
            Shops shop = array.get(i);
            System.out.println(shop.proNum+"  "+shop.proName+"    "+shop.proPrice+"  "+shop.count);
            totalCount+= shop.count;
        }
        System.out.println("总库存数："+totalCount);
    }
    //添加货物
    public  static void addCount(ArrayList<Shops> array){
        Shops shops = new Shops();
        Scanner in = new Scanner(System.in);
        System.out.println("请输入新商品的编号：");
        shops.proNum = in.nextInt();
        System.out.println("请输入新商品的名称：");
        shops.proName = in.next();
        System.out.println("请输入新商品单价：");
        shops.proPrice = in.nextInt();
        System.out.println("请输入商品库存：");
        shops.count = in.nextInt();
        array.add(shops);
    }
    //删除货物
    public  static void delete(ArrayList<Shops> array){
        System.out.println("请输入您要删除的商品编号：");
        Scanner in = new Scanner(System.in);
        int GoodId = in.nextInt();
        for (int i = 0; i < array.size(); i++) {
            Shops shops = array.get(i);
            if (shops.proNum == GoodId){
                array.remove(shops);
                System.out.println("商品信息删除完毕：");
                return;
            }
        }
        System.out.println("对不起，查无此商品！");
    }
    //修改货物
    public static void UpDate(ArrayList<Shops> array){
        System.out.println("请输入您要修改的商品信息：");
        Scanner in = new Scanner(System.in);
        int GoodId = in.nextInt();
        for (int i = 0; i < array.size(); i++) {
            Shops shops = array.get(i);
            if (shops.proNum==GoodId){
                System.out.println("请输入新的商品编号：");
                shops.proNum = in.nextInt();
                System.out.println("请输入新的商品名称：");
                shops.proName = in.next();
                System.out.println("请输入新的商品单价：");
                shops.proPrice = in.nextInt();
                System.out.println("请输入新的商品库存数量：");
                shops.count = in.nextInt();

            }
        }
        System.out.println("恭喜您，商品信息修改成功！");
    }
    public static  void exit(){
        System.out.println("退出程序！");
    }

}
